<template>
	<view>
		<comlist 
			title="创建健康现状评估" 
			:listtitle="listtitle" 
			:listLabel="listLabel" 
			:list="list" 
			:options="options" 
			:addpageUrl="'/pages/quickly/tcm/createTcm'" 
			@bindClick="bindClick" 
			@comSearch="comSearch" 
			@jump="jump" 
			:rBtn="rBtn" 
			@btnclick="btnclick"
			:nullData="nullData"
		>
		</comlist>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
	import comlist from '@/components/comlist/index.vue'
	import {filterData2} from "@/static/js/filter.js"
	export default {
		components:{comlist},
		data() {
			return {
				list: null,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' ,// 删除按钮背景  红的
					}
				}],
				listtitle:'中医体质辨识',
				listLabel:[
					{
						name:'评估编号：',
						key:'sn'
					},
					{
						name:'辨识结果：',
						key:'string'
					},
				],
				showModal:false,
				showContent:'',
				rBtn:{
					show:true,
					title:'查看报告'
				},
				page: 1,
				nullData:false,
				deleteList: '',
				SearchuserId:''
			}
		},
		onLoad() {
			this.getlist({pageNumb:1,pageSize:10})
		},
		onReachBottom(){
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist({pageNumb:this.page,pageSize:10,userId:this.SearchuserId})
		},
		methods:{
			comSearch(e) {
				this.page = 1
				this.SearchuserId = e == 'all'? '' : e.userId
				this.nullData = false
				this.deleteList = 1
				this.getlist({pageNumb:this.page,pageSize:10,userId:this.SearchuserId})
			},
			filterData2,
			getlist(data){
				const _this = this;
				_this.$api.tcmList(data).then(res=>{
					var data = res.data.result && res.data.result.elements.map((a) => {
						a.realName = a.userName;
						if(a.constitution){
							const constitution = JSON.parse(a.constitution)
							if(!constitution[0] && !constitution[1] && !constitution[2] && !constitution[3]){
								a.string = ''
							}else if(!constitution[3] && constitution[0]) {
								a.string = '为'+constitution[0]+'体质'
							}else{
								a.string = '为'+constitution[0]+(constitution[0] == '偏颇体质'?',':'体质,') +'以'+constitution[1]+'为主,' + '兼'+constitution[2]+'体质,' + '有'+constitution[3]+'倾向'
							}
						}
						return a
					});
					
					if(_this.deleteList == 1) {
						_this.list = []
						_this.list = data
						_this.deleteList = ''
					}else {
						_this.list = _this.list ? _this.list.concat(data) : data;
					}
					if(_this.list.length >= res.data.result.totalCount){
						_this.nullData = true;
					}
				})
			},
			bindClick(e){
				this.showModal = true
				this.showContent = '是否删除此计划'
				this.delItem = e
				// UserInfodelete
			},
			Modalconfirm(){
				this.$api.delTcmList(this.delItem.id).then((res)=>{
					if(res.data.returnCode == 200){
						uni.showToast({
							title:'删除成功',
							icon:'none'
						})
						this.deleteList = 1;
						this.nullData = false
						this.page = 1
						this.getlist({pageNumb:1,pageSize:10,userId:this.SearchuserId})
					}
				})
			},
			jump(item){
				!item.status || item.status == 1?
					uni.navigateTo({url:encodeURI('/pages/quickly/tcm/createTcm?id='+item.id)})
				:
					uni.navigateTo({url:'/pages/quickly/tcm/toView?id='+item.id})
			},
			btnclick(item){
				if(item.url){
					window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+item.url
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	
</style>
